package com.hzeport.bgs22emduty.inbound.api;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzeport.bgs22emduty.entity.ScreenWaitList;
import com.hzeport.bgs22emduty.entity.SecurityLog;
import com.hzeport.bgs22emduty.service.SecurityLogService;
import com.masa.common.core.base.BaseResult;
////////import com.masa.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 记录系统操作日志
 *
 * @author code generator
 * @date 2022-12-02 11:21:59
 */
@RestController
@AllArgsConstructor
@RequestMapping("/securitylog")
@Api(value = "securitylog", tags = "记录系统操作日志管理")
@Slf4j
public class SecurityLogController {

    private final SecurityLogService securityLogService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param securityLog 记录系统操作日志
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public BaseResult getSecurityLogPage(Page page, SecurityLog securityLog) {
        return BaseResult.ok(securityLogService.page(page, securityLog));
    }


    /**
     * 通过id查询记录系统操作日志
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    public BaseResult getById(@PathVariable("id") String id) {
        return BaseResult.ok(securityLogService.getById(id));
    }

    /**
     * 新增记录系统操作日志
     * @param securityLog 记录系统操作日志
     * @return R
     */
    @ApiOperation(value = "新增记录系统操作日志", notes = "新增记录系统操作日志")
    //////@SysLog(.*)
    @PostMapping
    public BaseResult save(@RequestBody SecurityLog securityLog) {
        return BaseResult.ok(securityLogService.save(securityLog));
    }

    /**
     * 修改记录系统操作日志
     * @param securityLog 记录系统操作日志
     * @return R
     */
    @ApiOperation(value = "修改记录系统操作日志", notes = "修改记录系统操作日志")
    //////@SysLog(.*)
    @PutMapping
    public BaseResult updateById(@RequestBody SecurityLog securityLog) {
        String id = securityLog.getId();
        if (StringUtils.isNotBlank(id)) {
            SecurityLog byId = securityLogService.getById(id);
            if (byId != null){
                securityLog.setRecVersion(byId.getRecVersion());
            }
        }
        return BaseResult.ok(securityLogService.updateById(securityLog));
    }

    /**
     * 通过id删除记录系统操作日志
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除记录系统操作日志", notes = "通过id删除记录系统操作日志")
    //////@SysLog(.*)
    @DeleteMapping("/{id}")
    public BaseResult removeById(@PathVariable String id) {
        return BaseResult.ok(securityLogService.removeById(id));
    }

}
